home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / mnet102.zip / MNET.DOC < prev    next >
Text File  |  1992-09-05  |  5KB  |  175 lines

  1.  
  2. ------------------------------------------------------------------------------
  3.    M     M  U    U  L      TTTTTTT  IIIIIII       NN   N  EEEEEE  TTTTTTT
  4.    MM   MM  U    U  L         T        I          N N  N  E          T
  5.    M M M M  U    U  L         T        I    ----  N  N N  EEE        T
  6.    M  M  M  U    U  L         T        I          N   NN  E          T
  7.    M     M  UUUUUU  LLLLLL    T     IIIIIII       N    N  EEEEEE     T   v1.02
  8. ------------------------------------------------------------------------------
  9. Written by: Mike Whitaker, Copyright 1992 Elite Software Productions
  10.  
  11. Multi-Net is a set of Turbo Pascal v6.0 routines which allow a programmer
  12. to add simple Networking/Multitasking File Sharing support to their products.
  13. Multi-Net is the most complete and the simplest to use of all that i have
  14. found.
  15.  
  16. WHY DO I NEED IT?
  17. If you are writing a software which can have more than 1 User on at once,
  18. you may run into problems (ie. BBS Software, Application, etc..). ie. If
  19. WorkStation #1 Is Inserting a Record in MNTEST.DAT while
  20. WorkStation #2 Is Deleting a Record within MNTEST.DAT, and no file sharing
  21. is available in the application then POW.. Who knows the results, besides
  22. knowing the file is going to be messed up.  This program does require the
  23. presence of SHARE.EXE (comes with DOS) resident in the Multiplex Environment
  24. (SHARE.EXE must be run).  These routines work only for FILEs and FILE of x
  25. and unfortunately not TEXT files, A Look at the Header of MNET.PAS:
  26.  
  27. Const MNVer    : String[4] = '1.01'; { Multi-Net Version }
  28.       MNLock   = 0;            { Process = LOCK FILE }
  29.       MNUnLock = 1;            { Process = UNLOCK FILE }
  30.  
  31. Var UseLocking,                { Use File Sharing? (Locking & Unlocking)
  32.     Give_IOError,              { Set Off TP's IOResult Function }
  33.     ShareLoaded    : Boolean;  { Is SHARE.EXE Loaded? }
  34.  
  35. (* Is Share Activated? Returns TRUE or FALSE and Sets SHARELOADED Variable *)
  36. Function  Share_Active : Boolean;
  37.  
  38. (* Set DOS Lock Retry by the Wait in MS and how many times to try.
  39.    REASON: If a file is locked and another workstation is trying to access it,
  40.            you'd most likely want it to wait til the other workstation is done
  41.            with that file so that you can access it next *)
  42. Function  DOS_LockRetry (Wait, Times : Word) : Word;
  43.  
  44. (* Lock/UnLock Entire File: F = File Variable; Process = MNLock or MNUnLock
  45.   to lock and unlock the file *)
  46. Function  LockFile (Var F; Process:Byte):Boolean;
  47.  
  48. (* Use Just like WRITE. F = File, Buf = Data Buffer }
  49. Procedure NWrite (Var F,Buf);
  50.  
  51. (* Use Just like READ. F = File, Buf = Data Buffer }
  52. Procedure NRead  (Var F,Buf);
  53.  
  54. (* Use Just like BLOCKWRITE, F = File, Buf = Data Buffer, Count = Bytes to
  55.    Write, Res = Bytes Written *)
  56. Procedure NBlockWrite (Var F,Buf; Count,Res:Word);
  57.  
  58. (* Use Just like BLOCKREAD, F = File, Buf = Data Buffer, Count = Bytes to
  59.    Read, Res = Bytes Read *)
  60. Procedure NBlockRead (Var F,Buf; Count,Res:Word);
  61.  
  62. (* Allows a user to send a Pascal String (S) to F (File) as an ASCIIZ String *)
  63. Procedure NWriteStr (Var F; S:String);
  64.  
  65. Examples on Use (see how not much is changed):
  66.  
  67. procedure Write_Read;
  68. type TRec = record
  69.        blank1:char;
  70.        blank2:char;
  71.        textstr:string[250];
  72.      end;
  73. var
  74.   F   : File of TRec;
  75.   TR  : TRec;
  76. begin
  77.   assign (F,'TEST.FIL');
  78.   reset (F);
  79.   if ioresult <> 0 then
  80.    rewrite (F);
  81.   write (F,TR);
  82.   seek (F,0);
  83.   read (F,TR);
  84.   close (F);
  85. end;
  86.  
  87. procedure Net_Write_Read;
  88. type TRec = record
  89.        blank1:char;
  90.        blank2:char;
  91.        textstr:string[250];
  92.      end;
  93. var
  94.   F   : File of TRec;
  95.   TR  : TRec;
  96. begin
  97.   assign (F,'TEST.FIL');
  98.   reset (F);
  99.   if ioresult <> 0 then
  100.    rewrite (F);
  101.   nwrite (F,TR);         <--- Changed to NWRITE
  102.   seek (F,0);
  103.   nread (F,TR);          <--- Changed to NREAD
  104.   close (F);
  105. end;
  106.  
  107. procedure BlockRead_Write;
  108. var
  109.   F   : File;
  110.   D   : Array [1..1000] Of Char;
  111.   O   : Word;
  112. begin
  113.   assign (F,'TEST.FIL');
  114.   rewrite (F,1);
  115.   blockwrite (F,D,sizeof(D),O);
  116.   seek (F,0);
  117.   blockread (F,D,sizeof(D),O);
  118.   close (F);
  119. end;
  120.  
  121. procedure Net_BlockRead_Write;
  122. var
  123.   F   : File;
  124.   D   : Array [1..1000] Of Char;
  125.   O   : Word;
  126. begin
  127.   assign (F,'TEST.FIL');
  128.   rewrite (F,1);
  129.   nblockwrite (F,D,sizeof(D),O);  <-- Changed to NBLOCKWRITE
  130.   seek (F,0);
  131.   nblockread (F,D,sizeof(D),O);   <-- Changed to NBLOCKREAD
  132.   close (F);
  133. end;
  134.  
  135. Do you use TEXT variables to write text files? There is a very simple way
  136. to get around and use these net routines.
  137.  
  138. Step 1: Make the TEXT a FILE of CHAR
  139. Step 2: Substitute Writeln for NWriteStr with #13#10 at end, and Write for
  140.         NWriteStr
  141. Step 3: Substitute ReadLn for NTextRLn and Read for NRead
  142. Step 4: Wasn't that easy?
  143.  
  144. procedure NTextRLn (var F; Var S:String);
  145. var
  146.   S2     : String;
  147.   Cnt    : Integer;
  148.   C      : Char;
  149. begin
  150.   S2 := '';
  151.   For Cnt := 1 To 255 Do Begin
  152.     NRead (F,C);
  153.     If C = #13 Then Begin
  154.       S := S2;
  155.       Exit;
  156.     End Else
  157.     S2 := S2 + C;
  158.   end;
  159.   S := S2;
  160. end;
  161.  
  162.  
  163. If you use this product in your code, all i ask is that you place me in
  164. your documentation or credits some where and you may use it freely.
  165.  
  166. For the Complete source and latest updates send $25 to:
  167.  
  168.   Mike Whitaker
  169.   P.O. Box 871958
  170.   Dallas,Tx  75287-1958
  171.  
  172.  
  173. REVISIONS:
  174.  v1.01 - Fixed NBlockWrite and NBLockRead with returning characters read.
  175.